// 把不同的工作 放到 不同的方法中
// this指向实例化后的对象
class ChinaMap {
    constructor() {
        console.log('实例化了');
        // 统一方案
        this.cube=null; //属性
        this.init(); //执行流程的管理方法
    }
    init() {
        // 三个对象的实例过程放在这里
        this.scene = new THREE.Scene();
        this.setCamera()  
        this.setRenderer()      
        const geometry = new THREE.BoxGeometry();
        const material = new THREE.MeshBasicMaterial({ 
            color: 0x00ff00 })
        this.cube = new THREE.Mesh(geometry, material)
        this.scene.add(this.cube)
        this.render()
        this.animate()
        var controller = new THREE.OrbitControls(this.camera, this.renderer.domElement);
    }
    setCamera() {
        this.camera = new THREE.PerspectiveCamera(
            75,
            window.innerWidth / window.innerHeight,
            0.1,
            1000
          )
        // 很精彩
        this.camera.position.z = 5;
        // this.camera.position.x = -2;
        // this.camera.position.y = -1;
    }
    setRenderer() {
        this.renderer = new THREE.WebGLRenderer()
        this.renderer.setSize(window.innerWidth, window.innerHeight)
        document.body.appendChild(this.renderer.domElement)
    }
    render() {
        this.renderer.render(this.scene, this.camera)
    }
    animate() {
        requestAnimationFrame(this.animate.bind(this))
        this.cube.rotation.x += 0.01
        this.cube.rotation.y += 0.01
        this.render()
    }
}